package com.sise.wangzhan;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * @Classname MyHttpRequest
 * @Description TODO    对原来请求的URI进行改写，所有请求都会转移到/hello
 * @Date 2020/4/2 10:40
 * @Created by wangzhan
 */
public class MyHttpRequest implements HttpRequest {

    private HttpRequest sourceRequest;

    public MyHttpRequest(HttpRequest sourceRequest) {
        this.sourceRequest = sourceRequest;
    }

    @Override
    public HttpMethod getMethod() {
        return sourceRequest.getMethod();
    }

    @Override
    public String getMethodValue() {
        return null;
    }

    @Override
    public URI getURI() {

        try {
            String oldUri = sourceRequest.getURI().toString();
            System.out.println("旧的URI："+oldUri+"+++++++++++++++++++++++++++++++++++++++");
            URI newUri = new URI("http://localhost:9000/hello");
            System.out.println("新的URI："+newUri+"+++++++++++++++++++++++++++++++++++++++");

            return newUri;
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        return sourceRequest.getURI();
    }

    @Override
    public HttpHeaders getHeaders() {
        return sourceRequest.getHeaders();
    }
}
